package com.mooer.app;

import java.util.ArrayList;
import java.util.List;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewTreeObserver.OnPreDrawListener;
import android.view.Window;
import android.widget.ImageView;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TabWidget;

import com.mooer.R;
import com.mooer.bean.Shop;
import com.mooer.utils.ui.UiUtils;

/**
 * @author pengfei.xu
 * @version 创建时间：2011-6-12 上午07:32:17 类说明
 */
public class Activities extends TabActivity implements OnClickListener {

	private TabHost tabHost;

	private TabWidget tabWidget;

	private ImageView currentActivity, oldActivity, newActivity;

	private List<View> vs;
	private OnPreDrawListener op;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activities);
		vs = new ArrayList<View>();
		oldActivity = (ImageView) findViewById(R.id.old_activity);
		currentActivity = (ImageView) findViewById(R.id.current_activity);
		newActivity = (ImageView) findViewById(R.id.new_activity);
		initTab();

		vs.add(currentActivity);
		vs.add(oldActivity);
		vs.add(newActivity);
		op = UiUtils.initButtonState(currentActivity);

	}

	private void initTab() {
		tabHost = getTabHost();
		Intent layout1intent = new Intent();
		layout1intent.setClass(this, ActivityCurrent.class);
		final TabHost.TabSpec layout1spec = tabHost.newTabSpec("current");
		layout1spec.setIndicator("");
		layout1spec.setContent(layout1intent);
		tabHost.addTab(layout1spec);

		Intent layout2intent = new Intent();
		layout2intent.setClass(this, ActivityOld.class);
		final TabHost.TabSpec layout2spec = tabHost.newTabSpec("old");
		layout2spec.setIndicator("");
		layout2spec.setContent(layout2intent);
		tabHost.addTab(layout2spec);

		Intent layout3intent = new Intent();
		layout3intent.setClass(this, ActivityNew.class);
		final TabHost.TabSpec layout3spec = tabHost.newTabSpec("new");
		layout3spec.setIndicator("");
		layout3spec.setContent(layout3intent);
		tabHost.addTab(layout3spec);

		tabWidget = tabHost.getTabWidget();
		for (int i = 0; i < tabWidget.getChildCount(); i++) {
			View view = tabWidget.getChildAt(i);
			view.setBackgroundColor(0);
		}
		tabHost.setOnTabChangedListener(new OnTabChangeListener() {

			@Override
			public void onTabChanged(String tabId) {
				if ("current".equals(tabId)) {
					UiUtils.buttonStateChange(vs, currentActivity, op);
				} else if ("old".equals(tabId)) {
					UiUtils.buttonStateChange(vs, oldActivity, op);
				} else if ("new".equals(tabId)) {
					UiUtils.buttonStateChange(vs, newActivity, op);
				}

			}
		});
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub

	}

}
